package com.cff.action;

import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

import com.cff.common.CacheMemory;
import com.cff.common.Constant;
import com.cff.common.SimpleFrame;
import com.cff.util.EventUtil;
import com.cff.util.SignTools;

public class SktAddMsgActionListener implements ActionListener {
	
	Panel controlPanel;

	public SktAddMsgActionListener(Panel controlPanel) {
		super();
		this.controlPanel = controlPanel;
	}


	@Override
	public void actionPerformed(ActionEvent e) {
		final JFrame tmpFrame = new JFrame();
		tmpFrame.setBounds(300, 300, 300, 200);
		tmpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		tmpFrame.setLayout(null);
		
		JLabel hsmIpLabel = new JLabel();
		hsmIpLabel.setBounds(20, 20, 80, 50);
		hsmIpLabel.setText("域:");
		
		JLabel hsmPortLabel = new JLabel();
		hsmPortLabel.setBounds(20, 70, 80, 50);
		hsmPortLabel.setText("默认值:");
		
		final JTextField hsmIpText = new JTextField();
		hsmIpText.setBounds(100, 35, 180, 20);
		
		final JTextField hsmPortText = new JTextField();
		hsmPortText.setBounds(100, 85, 180, 20);
		
		JButton okButton = new JButton("ok"); 
		okButton.setBounds(tmpFrame.getWidth()/2-50, tmpFrame.getHeight()-80, 50, 25);
		
		tmpFrame.add(hsmIpLabel);
		tmpFrame.add(hsmPortLabel);
		tmpFrame.add(hsmIpText);
		tmpFrame.add(hsmPortText);
		tmpFrame.add(okButton);
		
		//添加按钮监听
		okButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String labelName = hsmIpText.getText().trim();
				String textName = hsmPortText.getText().trim();
				if(labelName.matches("[0-9]{2}")){
					CacheMemory.makeNewMsg(controlPanel, labelName, textName);
				}

				tmpFrame.dispatchEvent(new WindowEvent(tmpFrame,WindowEvent.WINDOW_CLOSING) );
			}
           }
		);
		
		
		tmpFrame.setVisible(true);
	}

}
